package com.kyoto.administrator.mvpdemo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.kyoto.administrator.mvpdemo.baselib.mvpbase.baseImpl.BaseActivity;
import com.kyoto.administrator.mvpdemo.mvp.View.ILoginView;
import com.kyoto.administrator.mvpdemo.mvp.presenter.LoginPresenter;

public class MainActivity extends BaseActivity<LoginPresenter> implements ILoginView {

    private ProgressBar progressBar;
    private EditText username;
    private EditText password;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
        initdata();
    }

    @Override
    public LoginPresenter initPresenter() {
        return new LoginPresenter(this);
    }

    private void initview() {
        progressBar = findViewById(R.id.progress);
        username = findViewById(R.id.edit_user);
        password = findViewById(R.id.edit_pass);
        btn = findViewById(R.id.btn_login);
    }

    private void initdata() {
//        presenter = new LoginPresenter(this);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.validateCredentials(username.getText().toString(),password.getText().toString());
            }
        });
    }

    @Override
    public void showProgress() {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void setUsernameError() {
        username.setError("用户名错误");
    }

    @Override
    public void setPasswordError() {
        username.setError("密码错误");
    }

    @Override
    public void navigateToHome() {
        Toast.makeText(this,"login success",Toast.LENGTH_SHORT).show();
    }
}
